package guowenlong.golf.ui.friendlymatch;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import butterknife.BindView;
import butterknife.OnClick;
import com.github.jjobes.slidedatetimepicker.SlideDateTimeListener;
import com.github.jjobes.slidedatetimepicker.SlideDateTimePicker.Builder;
import guowenlong.golf.R;
import guowenlong.golf.ui.court.CourtListActivity;
import guowenlong.golf.ui.friend.myfriends.ContactsInfo;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import me.wenlong.mixutils.mvp.BaseActivity;

/**
 * des   : 描述
 * author: Administrator
 * email : guowenlong20000@gmail.com
 * time  : 2017年04月12日 上午 12:30.
 */

public class FriendlyMatchActivity extends BaseActivity {

  @BindView(R.id.tv_back)
  TextView tvBack;
  @BindView(R.id.ll_friendly_time)
  LinearLayout llFriendlyTime;
  @BindView(R.id.ll_friendly_address)
  LinearLayout llFriendlyAddress;
  @BindView(R.id.ll_friendly_name)
  LinearLayout llFriendlyName;
  @BindView(R.id.ll_friendly_play)
  LinearLayout llFriendlyPlay;
  @BindView(R.id.ll_friendly_almost)
  LinearLayout llFriendlyAlmost;
  @BindView(R.id.ll_friendly_scoring)
  LinearLayout llFriendlyScoring;
  @BindView(R.id.ll_friendly_caddy)
  LinearLayout llFriendlyCaddy;
  @BindView(R.id.ll_friendly_rule)
  LinearLayout llFriendlyRule;
  @BindView(R.id.ll_friendly_setting)
  LinearLayout llFriendlySetting;
  @BindView(R.id.ll_friendly_user)
  LinearLayout llFriendlyUser;
  @BindView(R.id.tv_time)
  TextView tvTime;
  @BindView(R.id.gv_friendly_match)
  GridView gvFriendlyMatch;
  @BindView(R.id.tv_start)
  TextView tvStart;
  @BindView(R.id.tv_notify)
  TextView tvNotify;
  @BindView(R.id.tv_friendly_hold)
  TextView tvFriendlyHold;
  @BindView(R.id.ll_friendly_qiudao)
  LinearLayout llFriendlyQiudao;
  @BindView(R.id.tv_play_game)
  TextView tvPlayGame;
  @BindView(R.id.tv_friendly_scoring)
  TextView tvFriendlyScoring;
  @BindView(R.id.tv_friendly_caddy)
  TextView tvFriendlyCaddy;
  @BindView(R.id.tv_friendly_setting)
  TextView tvFriendlySetting;

  @Override
  protected int getContentView(Bundle savedInstanceState) {
    return R.layout.activity_friendly_match;
  }

  @Override
  protected void initView(Bundle savedInstanceState) {

  }

  @Override
  protected void initData() {

  }

  private SimpleDateFormat mFormatter = new SimpleDateFormat("MM-dd aa hh:mm");

  private SlideDateTimeListener listener = new SlideDateTimeListener() {

    @Override
    public void onDateTimeSet(Date date) {
      tvTime.setText(mFormatter.format(date));
    }

    @Override
    public void onDateTimeCancel() {
    }
  };

  @OnClick({R.id.tv_back, R.id.ll_friendly_time, R.id.ll_friendly_address, R.id.ll_friendly_name,
      R.id.ll_friendly_play, R.id.ll_friendly_almost, R.id.ll_friendly_scoring,
      R.id.ll_friendly_user, R.id.tv_start, R.id.tv_notify,
      R.id.ll_friendly_caddy, R.id.ll_friendly_rule, R.id.ll_friendly_setting,
      R.id.ll_friendly_qiudao})
  public void onViewClicked(View view) {
    switch (view.getId()) {
      case R.id.tv_back:
        finish();
        break;
      case R.id.ll_friendly_time:
        new Builder(getSupportFragmentManager())
            .setListener(listener)
            .setInitialDate(new Date())
            .build()
            .show();
        break;
      case R.id.ll_friendly_address:
        startActivity(new Intent(this, CourtListActivity.class));
        break;
      case R.id.ll_friendly_user:
        startActivityForResult(new Intent(this, SelectedFriendActivity.class), 1);

        break;
      case R.id.ll_friendly_name:
        break;
      case R.id.ll_friendly_play:
        startActivityForResult(new Intent(this, PlaySettingActivity.class), 3);
        break;
      case R.id.ll_friendly_almost:
        break;
      case R.id.ll_friendly_scoring:
        startActivityForResult(new Intent(this, MainscoreActivity.class), 4);
        break;
      case R.id.ll_friendly_caddy:
        startActivityForResult(new Intent(this, MainscoreActivity.class), 5);
        break;
      case R.id.ll_friendly_rule:
        break;
      case R.id.ll_friendly_setting:
        startActivityForResult(new Intent(this, FriendlySettingActivity.class), 6);
        break;
      case R.id.ll_friendly_qiudao:
        startActivityForResult(new Intent(this, SelectedNumberActivity.class), 2);
        break;
      case R.id.tv_start:
        startActivityForResult(new Intent(this, ResulteTableActivity.class), 7);
        break;
      case R.id.tv_notify:
        Toast.makeText(this, "发送成功", Toast.LENGTH_SHORT).show();
        break;
    }
  }

  private List<Map<String, Object>> data_list = new ArrayList<Map<String, Object>>();

  private SimpleAdapter sim_adapter;
  private int[] icon = {R.mipmap.bg_login, R.mipmap.bg_login, R.mipmap.bg_login, R.mipmap.bg_login,
      R.mipmap.bg_login};

  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
      switch (requestCode) {
        case 1:
          data_list.clear();
          ContactsInfo contactsInfo = new ContactsInfo("我", "11111111111", "W", 14, 0);
          ArrayList<ContactsInfo> list = (ArrayList<ContactsInfo>) data
              .getSerializableExtra("list");
          ArrayList<ContactsInfo> contactsInfos = new ArrayList<>();
          contactsInfos.add(contactsInfo);
          contactsInfos.addAll(list);
          for (int i = 0; i < contactsInfos.size(); i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("image", icon[i]);
            map.put("text", contactsInfos.get(i).getName());
            data_list.add(map);
          }
          String[] from = {"image", "text"};
          int[] to = {R.id.image, R.id.text};
          sim_adapter = new SimpleAdapter(this, data_list, R.layout.item_friendly_match, from, to);
          gvFriendlyMatch.setAdapter(sim_adapter);
          break;
        case 2:
          tvFriendlyHold.setText(data.getStringExtra("hold_number"));
          break;
        case 3:
          tvPlayGame.setText(data.getStringExtra("action"));
          break;
        case 4:
          ArrayList<ContactsInfo> list4 = (ArrayList<ContactsInfo>) data
              .getSerializableExtra("list");
          tvFriendlyScoring.setText(list4.get(0).getName());
          break;
        case 5:
          ArrayList<ContactsInfo> list5 = (ArrayList<ContactsInfo>) data
              .getSerializableExtra("list");
          tvFriendlyCaddy.setText(list5.get(0).getName());
          break;
        case 6:
          tvFriendlySetting.setText(data.getStringExtra("action"));
          break;
      }
    }
    super.onActivityResult(requestCode, resultCode, data);
  }
}